package com.ifast.yuxin.service.impl;

import com.ifast.common.utils.InterfaceSendUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ifast.yuxin.dao.QuestionsDao;
import com.ifast.yuxin.domain.QuestionsDO;
import com.ifast.yuxin.service.QuestionsService;
import com.ifast.common.base.CoreServiceImpl;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * 
 * <pre>
 * 娱信竞技场数据基础表
 * </pre>
 * <small> 2019-02-06 21:14:49 | zhengyingjun</small>
 */
@Service
public class QuestionsServiceImpl extends CoreServiceImpl<QuestionsDao, QuestionsDO> implements QuestionsService {
    @Autowired
    private QuestionsDao questionsDao;
    @Override
    public String importInterface(List<Integer> list) {
        String result = "";
        int success = 0;
        int repeat = 0;
        int fail = 0;
        for (int i = 0; i <list.size() ; i++) {
            QuestionsDO question = new QuestionsDO();
            List<QuestionsDO> list1 = questionsDao.getQuestionDetailById(list.get(i));
             if(list1.size()>0){
                 question = list1.get(0);
                 String re = InterfaceSendUtil.interfaceOne(question.toString());
                 if(re == "\"成功上传1条\""||re.equals("\"成功上传1条\"")){
                     success ++;
                 }else if(re=="\"成功上传0条\""||re.equals("\"成功上传0条\"")){
                     repeat ++;
                 }else if(re=="\"参数错误\""||re.equals("\"参数错误\"")){
                     fail ++;
                     System.out.println("参数错误："+list.get(i));
                     log.error("数据出错："+list.get(i));
                 }
             }else{
                 question = null;
                 continue;
             }
        }
        SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String TimeString = time.format(new java.util.Date());
        result = TimeString+" 成功上传："+success+"条，"+"失败："+fail+"条，"+"重复："+repeat+"条";
        //todo 数据库建表记录操作日志
        return result;
    }
}
